package com.fastCms.business.frame.utils.gps;

import com.alibaba.fastjson.JSON;
import com.fastCms.business.frame.utils.HttpclientUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

public class GpsUtil {
    private static final String GET_TRACK = "http://www.gps09.com/api/TrackingByAPI.aspx?";

    public static TrackVO getTrack(String imei) {
        try {
            StringBuilder requestURL = new StringBuilder(GET_TRACK);
            requestURL.append("imei=");
            requestURL.append(imei);

            requestURL.append("&password=");
            requestURL.append("123456");

            requestURL.append("&mapType=");
            requestURL.append("google");

            requestURL.append("&key=");
            requestURL.append("2020YCHANGJIAN8SH3");

            String resp = HttpclientUtils.get(requestURL.toString());
            if (StringUtils.isNotBlank(resp)) {
                TrackVO trackVO = JSON.parseObject(resp, TrackVO.class);
                if (null != trackVO) {
                    trackVO.setStatus(trackVO.getStatus().substring(0, 1));
                    return trackVO;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        TrackVO track = getTrack("13808350053");
        System.out.println(track);
    }
}
